package core.network;

import core.db.DBWrapper;

public class DBSyncThread extends Thread {

	private long startTime;

	DBWrapper dbWrapper;

	public DBSyncThread(DBWrapper dbWrapper) {
		startTime = System.currentTimeMillis();
		this.dbWrapper = dbWrapper;
	}

	public void run() {
		double random = Math.random() + 0.5;
		long currentTime = System.currentTimeMillis();
		while (currentTime - startTime < DBWrapper.INTERVAL * random) {
			currentTime = System.currentTimeMillis();
			random = Math.random() + 0.5;
			if (currentTime - startTime > DBWrapper.INTERVAL * random) {
				startTime = currentTime;
				dbWrapper.updateGroupMembership();
			}
		}
	}
}
